/*
 * XtrazMessagePlugin.java
 *
 * Created on 11 ������� 2007 �., 0:54
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

// #sijapp cond.if protocols_ICQ is "true" #
// #sijapp cond.if modules_XSTATUSES is "true" #
package org.jimm.protocol.icq.plugin;

import org.jimm.comm.*;
import org.jimm.comm.GUID;

import org.jimm.message.PlainMessage;
import org.jimm.message.PluginMessage;
import org.jimm.protocol.Protocol;
import org.jimm.protocol.icq.*;
import org.jimm.protocol.icq.action.*;

/**
 * @author vladimir
 */
public class XtrazMessagePlugin {
    private long cookie1;
    private long cookie2;
    protected IcqContact rcvr;

    public void setCookie(long c1, long c2) {
        cookie1 = c1;
        cookie2 = c2;
    }

    public long getCookie1() {
        return cookie1;
    }

    public long getCookie2() {
        return cookie2;
    }

    public IcqContact getRcvr() {
        return rcvr;
    }


    String msg;
    private static final String NAME = "Script Plug-in: Remote Notification Arrive";

    /**
     * Creates a new instance of XtrazMessagePlugin
     */
    public XtrazMessagePlugin(IcqContact rcvr, String msg) {
        this.rcvr = rcvr;
        this.msg = msg;
    }

    public static final GUID XTRAZ_GUID = new GUID(new byte[]{(byte) 0x3b, (byte) 0x60, (byte) 0xb3, (byte) 0xef, (byte) 0xd8, (byte) 0x2a, (byte) 0x6c, (byte) 0x45, (byte) 0xa4, (byte) 0xe0, (byte) 0x9c, (byte) 0x5a, (byte) 0x5e, (byte) 0x67, (byte) 0xe8, (byte) 0x65});

    public GUID getGUID() {
        return XTRAZ_GUID;
    }


    public void activate(Protocol p) {
        PlainMessage awayReq = new PluginMessage(p, this);
        ((Icq) p).requestSimpleAction(new SendMessageAction(awayReq));
    }


    public boolean isAck() {
        return msg.startsWith("<N>");
    }


    public byte[] getData() {
        byte[] str = StringConvertor.stringToByteArrayUtf8(msg);
        Util buffer = new Util();
        buffer.writeDWordLE(str.length);
        buffer.writeByteArray(str);
        return buffer.toByteArray();
    }

    public static final int MGTYPE_SCRIPT_NOTIFY = 0x0008;

    public int getCommand() {
        return MGTYPE_SCRIPT_NOTIFY;
    }

    public String getSubTypeText() {
        return NAME;
    }
}
// #sijapp cond.end#
// #sijapp cond.end#
